#include "AddPieceNetworkEvent.h"
#include "Well.h"

AddPieceNetworkEvent::AddPieceNetworkEvent(long pieceId, const Position& position, Color color)
{
    message.header.code = NetworkEvent::SERVER_ADD_PIECE;
    message.header.sizeOfData = sizeof(message) - sizeof(message.header);
    message.data.pieceId = pieceId;
    message.data.x = position.x;
    message.data.y = position.y;
    message.data.colorR = color.r;
    message.data.colorG = color.g;
    message.data.colorB = color.b;
}

AddPieceNetworkEvent::AddPieceNetworkEvent(const Header& header, const Data& data)
{
    message.header = header;
    message.data = data;
}

AddPieceNetworkEvent::~AddPieceNetworkEvent()
{
}

void* AddPieceNetworkEvent::getMessageBlob()
{
    return &message;
}

void AddPieceNetworkEvent::visitWell(Well* well) const
{
    well->handleAddPieceEvent(message.data.pieceId, Position(message.data.x, message.data.y),
            Color(message.data.colorR, message.data.colorG, message.data.colorB));
}

size_t AddPieceNetworkEvent::getMessageBlobSize()
{
    return sizeof(message);
}
